package com.yalisanda.edu.service.impl;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yalisanda.edu.entity.EduStudent;
import com.yalisanda.edu.entity.vo.*;
import com.yalisanda.edu.mapper.StudentMapper;
import com.yalisanda.edu.service.EduStudentService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.ylsdxy.model.response.CustomPage;

import javax.annotation.Resource;
import java.util.List;

@Service
public class EduStudentServiceImpl implements EduStudentService {

    @Resource
    private StudentMapper studentMapper;


    @Transactional
    @Override
    public boolean insertStudent(EduStudent eduStudent) {
        return studentMapper.insertStudent(eduStudent);
    }

    @Override
    public List<EduStudentSourceVo> findResource() {
        return studentMapper.findResource();
    }

    @Override
    public List<StudentCountGroupByDateVo> findCountGroupByDate() {
        return studentMapper.findCountGroupByDate();
    }

    @Override
    public CustomPage<List<EduStudent>> findEduStudentByPage(int page, int size) {
        PageHelper.startPage(page, size);
        List<EduStudent> eduStudentByPage = studentMapper.findEduStudentByPage();
        PageInfo<EduStudent> pageInfo = new PageInfo<>(eduStudentByPage);

        CustomPage<List<EduStudent>> customPage = CustomPage.<List<EduStudent>>builder()
                .currentPage(page)
                .size(size)
                .total(pageInfo.getTotal())
                .data(eduStudentByPage).build();
        return customPage;
    }

    @Override
    public EduStudent findEduStudentById(Integer id) {
        return studentMapper.findEduStudentById(id);
    }

    @Override
    public EduStudentCourseInfoVo findEduStudentCourseInfoByStuId(Integer stuId) {
        return studentMapper.findEduStudentCourseInfoByStuId(stuId);
    }

    @Override
    public EduStudentOrderVo findEduStudentOrderByStuId(Integer stuId) {
        return studentMapper.findEduStudentOrderByStuId(stuId);
    }

    @Override
    public SignedConditionVo findEduSignedConditionByStuId(Integer stuId) {
        return studentMapper.findEduSignedConditionByStuId(stuId);
    }
}
